package com.bjc.base.web;

import com.bjc.base.bean.ResultVO;
import com.bjc.base.core.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.bjc.base.service.IBookStockService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import com.bjc.base.bean.request.BookStockReqVO;
import com.bjc.base.bean.response.BookStockVO;

/**
 * <p>
 * 绘本库存 前端控制器
 * </p>
 *
 * @author 许自辉
 * @since 2018-06-10
 */
@RestController
@RequestMapping("api/book")
@Api(value = "bookStock-api", tags = { "绘本库存相关接口" })
public class BookStockController {

    @Autowired
    private IBookStockService bookStockService;

	@ApiOperation("分页查询绘本库存")
	@GetMapping("bookStock/findPage")
	public ResultVO getBookStockPage(@RequestParam("pageNum") int pageNum, @RequestParam("pageSize") int pageSize,
			BookStockReqVO bookStockReqVO) {
		PageHelper.startPage(pageNum, pageSize);
		List<BookStockVO> bookStockVOs = bookStockService.getList(bookStockReqVO);
		return ResultGenerator.getSuccess(new PageInfo<BookStockVO>(bookStockVOs));
	}
	
	@ApiOperation("分页查询绘本库存")
	@GetMapping("bookStock/find")
	public ResultVO getBookStocke(BookStockReqVO bookStockReqVO) {
		BookStockVO bookStockVO = bookStockService.get(bookStockReqVO);
		return ResultGenerator.getSuccess(bookStockVO);
	}

	@ApiOperation("添加绘本库存")
	@PostMapping("bookStock/create")
	public ResultVO createBookStock(@RequestBody BookStockReqVO bookStockReqVOs) {
		int count = bookStockService.insert(bookStockReqVOs);
		return ResultGenerator.getInsertSuccess(count);
	}

	@ApiOperation("更新绘本库存")
	@PutMapping("bookStock/update")
	public ResultVO updateBookStock(@RequestBody BookStockReqVO bookStockReqVOs) {
		int count = bookStockService.update(bookStockReqVOs);
		return ResultGenerator.getUpdateSuccess(count);
	}

	@ApiOperation("批量删除绘本库存")
	@DeleteMapping("bookStock/deleteList")
	public ResultVO deleteBookStock(@ApiParam(value = "bookStock id集合") @RequestBody int[] ids) {
		int count = bookStockService.deleteList(ids);
		return ResultGenerator.getDeleteSuccess(count);
	}

}
